package com.liuxinlong.modules.system.service.impl;

import com.liuxinlong.modules.dao.UserDao;
import com.liuxinlong.modules.dao.UserFollowDao;
import com.liuxinlong.modules.entity.UserFollow;
import com.liuxinlong.modules.system.service.UserFollowService;
import com.liuxinlong.utils.ObjectUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 用户关注实现类
 *
 * @author liuxinlong@hotwater.com.cn
 * @version 1.0.0
 * @since 2023-04-20
 */
@Service
@Slf4j
public class UserFollowServiceImpl implements UserFollowService {

    @Autowired
    private UserDao userDao;

    @Autowired
    private UserFollowDao userFollowDao;

    @Override
    public List<Map<String,Object>> getUserFollowList(Map<String, Object> queryParam) {
        List<UserFollow> originalList= userFollowDao.getUserFollowList(queryParam);
        List<Map<String,Object>> dataList = new ArrayList<>(originalList.size());
        int sort = (int) queryParam.get("startNum") + 1;
        for (UserFollow userFollow: originalList) {
            Map<String,Object> item = ObjectUtils.object2Map(userFollow);
            item.put("sort",sort);
            dataList.add(item);
            sort++;
        }
        return dataList;
    }

    @Override
    public List<Map<String,Object>> getUserFansList(Map<String, Object> queryParam) {
        List<UserFollow> originalList= userFollowDao.getUserFansList(queryParam);
        List<Map<String,Object>> dataList = new ArrayList<>(originalList.size());
        int sort = (int) queryParam.get("startNum") + 1;
        for (UserFollow userFollow: originalList) {
            Map<String,Object> item = ObjectUtils.object2Map(userFollow);
            item.put("sort",sort);
            dataList.add(item);
            sort++;
        }
        return dataList;
    }
}
